﻿using System.Linq;
using UniMana.Utils.Controls;
using UniMana.Utils.Configs;
using UniMana.Data;

namespace UniMana.Data
{
    public class Catalogue_RuleNameViInfo_Chi
    {
        private DBMain m_data = new DBMain();
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }

        public Catalogue_RuleNameVi Properties
        {
            get { return m_bds.Current as Catalogue_RuleNameVi; }
        }

        /// <summary>
        /// Lấy dữ liệu với ID hoặc Key
        /// </summary>
        /// <param name="DefaultKey"></param>
        public Catalogue_RuleNameViInfo_Chi(int key = -1)
        {
            var IQuery = m_data.m_DCSave.Catalogue_RuleNameVis.Where(tb => tb.Catalogue_RuleNameViKey == key);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Catalogue_RuleNameVi();
                m_bds.Add(Row);
            }
        }
    }
}
